from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from myutil import globalvar as gl, logs
from ui.app_about_form import Ui_Frame as app_about_frame


class app_about_form(QWidget, app_about_frame):
    def __init__(self, parent=None):
        super(app_about_form, self).__init__(parent)
        self.setupUi(self)

        self.init()

        self.down_update_pushButton.clicked.connect(self.down_update_event)

    def init(self):
        logs.logs_print("关于软件窗口初始化")
        self.jwc_app_update_url = None
        self.now_app_version_label.setText(gl.get_value("app_version"))

        try:
            a = gl.get_value("mysql_diver")
            res1 = a.get_find_list("select `value` from app_key_value where `key`='jwc_app_update_version'")
            self.new_app_version_label.setText(res1[0]["value"])

            res2 = a.get_find_list("select `value` from app_key_value where `key`='jwc_app_update_info'")
            self.textBrowser.setText(res2[0]["value"])

            res3 = a.get_find_list("select `value` from app_key_value where `key`='jwc_app_update_url'")
            self.jwc_app_update_url = res3[0]["value"]
        except:
            pass
        pass

    def down_update_event(self):
        logs.logs_print("下载更新")
        if str(self.new_app_version_label.text()) == str(self.now_app_version_label.text()):
            self.down_update_pushButton.setText("无需下载更新，当前版本是最新的")
        else:
            QtGui.QDesktopServices.openUrl(QtCore.QUrl(self.jwc_app_update_url))
